
/*
 * Copyright (C) Zhu Jiashun
 * Copyright (C) Zaver
 */

#ifndef RIO_H
#define RIO_H

#include <sys/types.h>

#define RIO_BUFSIZE 8192 // 缓冲区大小

/*
* reference the implementation in CSAPP
*/

// robust IO
typedef struct
{
    int rio_fd;                /* descriptor for this internal buf 文件描述符 */
    ssize_t rio_cnt;           /* unread bytes in internal buf 未读字节数 */
    char *rio_bufptr;          /* next unread byte in internal buf 下一个未读字节 */
    char rio_buf[RIO_BUFSIZE]; /* internal buffer 内部缓冲区 */
} rio_t;

ssize_t rio_readn(int fd, void *usrbuf, size_t n);             // 读 fd n 字节
ssize_t rio_writen(int fd, void *usrbuf, size_t n);            // 写 n 字节
void rio_readinitb(rio_t *rp, int fd);                         // 初始化
ssize_t rio_readnb(rio_t *rp, void *usrbuf, size_t n);         // 读 rio n 字节
ssize_t rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen); // 读 rio 行数据

#endif
